﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Audio;

namespace Dungeon_Dive
{
    /// <summary>
    /// Contentmanager is intended to manage assets required by different
    /// components of a game.
    /// </summary>
    class ContentManager : DrawableGameComponent
    {
        public SpriteBatch SpriteBatch { get; set; }
        public SpriteFont Font { get; set; }        // so far the only font used

        public Song Bgmusic;    // bacground music

        public Dictionary<String, SoundEffect> SoundEffects;

        Game parentGame;
        Log log;

        /// <summary>
        /// ContentManager constructor.
        /// </summary>
        /// <param name="game">Game instance this components belongs to</param>
        public ContentManager(Game game) : base(game)
        {
            parentGame = game;
        }

        public override void Initialize()
        {
            SoundEffects = new Dictionary<string,SoundEffect>();
            log = (Log)parentGame.Services.GetService(typeof(Log));
            log.Write("ContentManager.Init()");
            base.Initialize();
        }

        /// <summary>
        /// Loads content for ContentManager, including assets for use by other game components.
        /// </summary>
        protected override void LoadContent()
        {
            log.Write("ContentManager.LoadContent()");
            GraphicsDeviceManager gfxMan = (GraphicsDeviceManager)parentGame.Services.GetService(typeof(GraphicsDeviceManager));
            SpriteBatch = new SpriteBatch(gfxMan.GraphicsDevice);
            if (SpriteBatch == null) log.Write("ContentManager.SpriteBatch creation failed");
            Font = parentGame.Content.Load<SpriteFont>("Fonts\\Debugfont");
            Bgmusic = parentGame.Content.Load<Song>("Audio\\Beduiinipop");

            SoundEffects["playerWalk"] = parentGame.Content.Load<SoundEffect>("Audio\\step");
            SoundEffects["powerup"] = parentGame.Content.Load<SoundEffect>("Audio\\powerup");
            SoundEffects["swordhit"] = parentGame.Content.Load<SoundEffect>("Audio\\swordhit");
            SoundEffects["portal"] = parentGame.Content.Load<SoundEffect>("Audio\\portal");
            base.LoadContent();
        }
    }
}
